<template>
	<view class="">
		<template v-if="list.length != 0">
			<view class="listbg" v-for="(item,index) in list" :key="index" v-if="item.evaluate_date">
				<template v-if="item.allNum*1 > 1">
					<view class="listitem" @click="goinfo">
						<view class="tit">
							<text>{{item.market.mar_name || '暂无'}}-{{item.groupOrder.staffSimpleInfo[0].merchantField.mer_name || '暂无'}}</text>
							<text>已完成</text>
						</view>
						<view class="gray">下单时间: {{item.create_date || '暂无'}}</view>
						<view class="goods">
							<view class="imgbg">
								<image v-if="i <= 4" :src="ele" v-for="(ele,i) in item.allShoppingList" :key="index">
								</image>
								<image v-if="item.allNum >= 4" class="dian" src="../static/icon_296@2x.png" mode="">
								</image>
							</view>
							<view class="price">
								<view class="">￥<text>{{item.groupOrder.pay_price || '0'}}</text></view>
								<text>共{{item.total || '0'}}件</text>
							</view>
						</view>
						<view class="goodsbtn">
							<view class="" @click.stop="look(item)">查看评论</view>
						</view>
					</view>
				</template>
				<template v-else>
					<view class="listitem" @click="goinfo(item.id)">
						<view class="tit">
							<text>{{item.market.mar_name || '暂无'}}-{{item.groupOrder.staffSimpleInfo[0].merchantField.mer_name || '暂无'}}</text><text>已完成</text>
						</view>
						<view class="goods goods2">
							<image :src="item.allShoppingList[0]" mode=""></image>
							<view class="one">
								<text>{{item.shoppingText || '暂无介绍'}}</text>
								<text class="gray">下单时间: {{item.create_date || '暂无'}}</text>
							</view>
							<view class="price price2">
								<view class="">￥<text>{{item.groupOrder.pay_price || '0'}}</text></view>
								<text>共{{item.total || '0'}}件</text>
							</view>
						</view>
						<view class="realpay">
							实付金额:￥<text>{{item.groupOrder.total_price || '0'}}</text>
						</view>
						<view class="goodsbtn">
							<view @click.stop="look(item)">查看评论</view>
						</view>
					</view>
				</template>
			</view>
		</template>
		<view class="nomore" v-else>
			<image src="../static/icon_294@2x.png" mode=""></image>
			<text>暂时没有任何帮买订单</text>
			<text>去订单中心帮买</text>
			<view class="">订单中心</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadingType: 0, //分页
				goData: {
					status: 3, //帮买完成
					page: 1,
					task_date: '', //时间段
				}, //提交信息
				visible: false,
				date: '',
				list: [1]
			}
		},
		onLoad(e) {},
		onShow() {
			this.goData.page = 1;
			this.loadingType = 0;
			this.list = [];
			// 获取列表
			this.getList();
		},
		watch: {
			//监听状态栏
			date(newValue) {
				this.loadingType = 0;
				this.goData.page = 1;
				this.list = [];
				this.getList();
			}
		},
		//上拉加载
		onReachBottom: function() {
			if (this.loadingType == 2) {
				return uni.showToast({
					title: '没有更多了',
					icon: 'none'
				})
			}
			if (this.loadingType != 0) { //loadingType!=0;直接返回
				return false;
			}
			if (this.option == 2) {
				return false;
			}
			this.goData.page++;
			uni.showNavigationBarLoading(); //显示加载动画				
			this.getList(); //请求
		},
		methods: {
			// 查看评论
			look(item) {
				let data = JSON.stringify(item);
				uni.setStorageSync('data55', data);
				uni.navigateTo({
					url: "/P_buyer/mine/evaluate_look"
				})
			},
			getList() {
				this.$request('buyer/task_lst', {
					...this.goData,
				}, 'GET').then(res => {
					console.log(res, '订单列表');
					if (res.status == 200) {
						uni.hideNavigationBarLoading(); //关闭加载动画
						//如果长度小于等于0说明没有分页
						if (res.data.data.length < 15) {
							this.loadingType = 2; //没有更多了	
						} else {
							this.loadingType = 0; //请求成功让他返回上拉加载	
						}
						this.list = [...res.data.data];
						// 订单处理
						// 循环外层任务订单
						this.list.forEach((ele, index) => {
							//不是换货订单的情况下
							if (ele.task_type == 1) {
								let num = 0; //商品种类数量
								let total = 0; //商品总数
								let shoppingList = []; //商品图片
								let shoppingText = []; //介绍
								//循环商品总订单里面的子订单
								ele.groupOrder.staffSimpleInfo.forEach(ele2 => {
									//商品种类数量
									num += ele2.simpleOrderProduct.length;
									//商品总数
									total += ele2.total_num
									//商品图片
									ele2.simpleOrderProduct.forEach(ele4 => {
										// if (ele4.is_barter == 0) {
											if (ele4.simpleCartInfo.image) {
												shoppingList.push(ele4.simpleCartInfo
													.image);
											}
											if (ele4.simpleCartInfo.simpleCartInfo) {
												shoppingText.push(ele4.simpleCartInfo
													.simpleCartInfo);
											}
										// }
									})

								})
								this.$set(this.list[index], 'allNum', num);
								this.$set(this.list[index], 'allShoppingList', shoppingList);
								this.$set(this.list[index], 'total', total);
								this.$set(this.list[index], 'shoppingText', shoppingText);
							}
							//上面是正常订单
							//下面是退换订单
							if (ele.task_type == 4) {
								let num = 0; //商品种类数量
								let total = 0; //商品总数
								let shoppingList = []; //商品图片
								let shoppingText = []; //介绍
								//循环商品总订单里面的子订单
								ele.groupOrder.staffSimpleInfo.forEach(ele2 => {
									//循环子单的商品列表
									ele2.simpleOrderProduct.forEach(ele4 => {
										// is_barter不等于0
										if (ele4.is_barter != 0) {
											//商品种类数 is_barter不等于0
											num += 1;
											total += ele4.product_num;
											if (ele4.simpleCartInfo.image) {
												shoppingList.push(ele4.simpleCartInfo
													.image);
											}
											if (ele4.simpleCartInfo.simpleCartInfo) {
												shoppingText.push(ele4.simpleCartInfo
													.simpleCartInfo);
											}
										}
									})
								})
								this.$set(this.list[index], 'allNum', num);
								this.$set(this.list[index], 'allShoppingList', shoppingList);
								this.$set(this.list[index], 'total', total);
								this.$set(this.list[index], 'shoppingText', shoppingText);
							}
						})
					}
				})
			},
			goinfo() {
				uni.navigateTo({
					url: "../order_center/orderinfo"
				})
			},
		}
	}
</script>

<style>
	.listbg {
		width: 690rpx;
		margin-left: 30rpx;
		margin-top: 30rpx;


	}

	.realpay {
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		display: flex;
		justify-content: flex-end;
		align-items: baseline;
		margin-top: 6rpx;
	}

	.realpay text {
		font-size: 36rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.goodsbtn {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		margin-top: 20rpx;
	}

	.goodsbtn>view {
		width: 160rpx;
		height: 60rpx;
		background: linear-gradient(64deg, #2BCCA5, #22B591);
		box-shadow: 0px 4rpx 6rpx 0px rgba(20, 187, 146, 0.4);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #FFFFFF;
	}

	.listitem {
		width: 690rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-top: 30rpx;
		box-sizing: border-box;
		padding: 30rpx;
	}

	.tit {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		align-items: center;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.tit text:nth-of-type(2) {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F83535;
	}

	.gray {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
		margin-top: 10rpx;
	}

	.price2>view,
	.price2>view text {
		font-size: 26rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400 !important;
		color: #333333 !important;
	}

	.price2>text {
		margin-top: 4rpx;
		font-size: 22rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999 !important;
	}

	.goods2>image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
		/* background: #18BC37; */
		margin-right: 20rpx;

	}

	.one {
		display: flex;
		flex-direction: column;
	}

	.one>text:nth-of-type(1) {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		line-height: 36rpx
	}

	.goods {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 12rpx;
	}

	.price {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F83535;
	}

	.price>view text {
		font-size: 36rpx;

		font-weight: bold;

	}

	.price>text {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.listitem:first-child {
		margin-top: 0;
	}

	.imgbg {
		display: flex;
		align-items: center;
	}

	.imgbg .dian {
		width: 30rpx;
		height: 8rpx;
	}

	.imgbg image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		/* background: #18BC37; */
		margin-right: 10rpx;
	}

	page {
		background: #F5F5F5;
	}

	.box {
		width: 750rpx;
		height: 160rpx;
		overflow: hidden;
		background: linear-gradient(180deg, #109C7A 0%, #109C7A 100%);
		position: relative;
	}

	.box view:nth-of-type(2) {
		width: 100%;
		height: 40rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		position: absolute;
		bottom: 0;
		background: #F5F5F5;
	}

	.timesc {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		margin-top: 36rpx;
		margin-left: 30rpx;
	}

	.timesc image {
		width: 36rpx;
		height: 36rpx;
		margin-left: 2rpx;
	}

	.nomore {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
		overflow: hidden;
	}

	.nomore image {
		width: 306rpx;
		height: 352rpx;
		margin-top: 90rpx;
	}

	.nomore text:nth-of-type(1) {
		font-size: 34rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #333333;
		margin-bottom: 30rpx;
	}

	.nomore>view {
		font-size: 32rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #FFFFFF;
		width: 300rpx;
		height: 100rpx;
		background: linear-gradient(64deg, #2BCCA5, #22B591);
		box-shadow: 0px 4rpx 6rpx 0px rgba(20, 187, 146, 0.4);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 130rpx;
	}
</style>
